package com.kaiwukj.android.mcas.base;

import android.app.Activity;
import android.content.Intent;
import android.util.Log;

import com.kaiwukj.android.mcas.base.delegate.IFragment;
import com.kaiwukj.android.mcas.mvp.IPresenter;
import com.kaiwukj.android.mcas.mvp.IView;

import javax.inject.Inject;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;


/**
 * Copyright © KaiWu Technology Company
 *
 * @author Haife
 * @job Android Development
 * @company KW | 开物科技
 * @time 2019/7/1
 * @desc 因为 Java 只能单继承, 所以如果要用到需要继承特定 @{@link Fragment} 的三方库, 那你就需要自己自定义 @{@link Fragment} 比如实现侧滑功能
 * 继承于这个特定的 @{@link Fragment}, 然后再按照 {@link BaseMVPFragment} 的格式, 将代码复制过去, 记住一定要实现{@link IFragment}
 */
public abstract class BaseMVPFragment<P extends IPresenter> extends SimpleFragment implements IView {

    @Inject
    @Nullable
    protected P mPresenter;//如果当前页面逻辑简单, Presenter 可以为 null

    @Override
    public void onDestroy() {
        Log.d("BaseMVPFragment","---------onDestroy--------");
        if (mPresenter != null) mPresenter.detachView();//释放资源
        this.mPresenter = null;
        super.onDestroy();
    }

    @Override
    public void onDetach() {
        super.onDetach();
        mContext = null;
    }

    @Override
    public void showMessage(@NonNull String msg) {
        super.showMessage(msg);
    }

    @Override
    public void killMyself() {
        Activity mySelf = getActivity();
        if (mySelf != null) {
            mySelf.finish();
        }
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        startActivity(intent);
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void onTaskErr(int taskId) {

    }
}
